#include "Shape.h"

void Shape::PlaceAbove(Shape* target, boolean centerOnTarget) {
	float verticalDistance = XMVectorGetY(target->GetHighest()) - XMVectorGetY(this->GetLowest());
    if(centerOnTarget)
		Translation = XMVectorSet(XMVectorGetX(target->GetCenter()),
			                      XMVectorGetY(GetCenter()) + verticalDistance,
							      XMVectorGetZ(target->GetCenter()),
								  0.0f);
    else
        Translation = XMVectorSet(XMVectorGetX(GetCenter()),
		                          XMVectorGetY(GetCenter()) + verticalDistance,
						          XMVectorGetZ(GetCenter()),
								  0.0f);
}

void Shape::PlaceBelow(Shape* target, boolean centerOnTarget) {
    float verticalDistance = XMVectorGetY(this->GetHighest()) - XMVectorGetY(target->GetLowest());
    if(centerOnTarget)
		Translation = XMVectorSet(XMVectorGetX(target->GetCenter()),
			                      XMVectorGetY(GetCenter()) - verticalDistance,
						          XMVectorGetZ(target->GetCenter()),
								  0.0f);
    else
		Translation = XMVectorSet(XMVectorGetX(GetCenter()),
		                          XMVectorGetY(GetCenter()) - verticalDistance,
							      XMVectorGetZ(GetCenter()),
								  0.0f);
}

void Shape::PlaceLeftOf(Shape* target, boolean centerOnTarget) {
    float horizontalDistance = XMVectorGetX(this->GetHighest()) - XMVectorGetX(target->GetLowest());
    if(centerOnTarget)
		Translation = XMVectorSet(XMVectorGetX(GetCenter()) - horizontalDistance,
			                      XMVectorGetY(target->GetCenter()),
							      XMVectorGetZ(target->GetCenter()),
								  0.0f);
    else
		Translation = XMVectorSet(XMVectorGetX(GetCenter()) - horizontalDistance,
		                          XMVectorGetY(GetCenter()),
							      XMVectorGetZ(GetCenter()),
								  0.0f);
}

void Shape::PlaceRightOf(Shape* target, boolean centerOnTarget) {
    float horizontalDistance = XMVectorGetX(this->GetHighest()) - XMVectorGetX(target->GetLowest());
    if(centerOnTarget)
		Translation = XMVectorSet(XMVectorGetX(GetCenter()) + horizontalDistance,
			                      XMVectorGetY(target->GetCenter()),
							      XMVectorGetZ(target->GetCenter()),
								  0.0f);
    else
		Translation = XMVectorSet(XMVectorGetX(GetCenter()) + horizontalDistance,
		                          XMVectorGetY(GetCenter()),
							      XMVectorGetZ(GetCenter()),
								  0.0f);
}

void Shape::PlaceInFrontOf(Shape* target, boolean centerOnTarget) {
    float depthDistance = XMVectorGetZ(this->GetHighest()) - XMVectorGetZ(target->GetLowest());
    if(centerOnTarget)
		Translation = XMVectorSet(XMVectorGetX(target->GetCenter()),
			                      XMVectorGetY(target->GetCenter()),
							      XMVectorGetZ(GetCenter()) - depthDistance,
								  0.0f);
    else
		Translation = XMVectorSet(XMVectorGetX(GetCenter()),
		                          XMVectorGetY(GetCenter()),
							      XMVectorGetZ(GetCenter()) - depthDistance,
								  0.0f);
}

void Shape::PlaceBehind(Shape* target, boolean centerOnTarget) {
    float depthDistance = XMVectorGetZ(this->GetHighest()) - XMVectorGetZ(target->GetLowest());
    if(centerOnTarget)
		Translation = XMVectorSet(XMVectorGetX(target->GetCenter()),
			                      XMVectorGetY(target->GetCenter()),
							      XMVectorGetZ(GetCenter()) + depthDistance,
								  0.0f);
    else
		Translation = XMVectorSet(XMVectorGetX(GetCenter()),
		                          XMVectorGetY(GetCenter()),
							      XMVectorGetZ(GetCenter()) + depthDistance,
								  0.0f);
}